package com.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.demo.controller.from.MovieTicketingsFrom;
import com.demo.model.MovieTicketing;
import com.demo.service.MovieTicketingService;
import com.demo.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 杨森
 * @since 2022-04-06
 */
@RestController
@RequestMapping("/movieTicketing")
@Api(value = "票务",tags = "票务")
public class MovieTicketingController {
    @Resource
    private MovieTicketingService movieTicketingService;

    @PostMapping("/addMovieTicketings")
    @ApiOperation(value = "创建票务",notes = "创建票务")
    public Result<Boolean> addMovieTicketings(@RequestBody MovieTicketingsFrom movieTicketings){
        Boolean aBoolean = movieTicketingService.addMovieTicketings(movieTicketings.getMovieTicketings());
        return Result.getInstance(Boolean.class).setData(aBoolean);
    }

    @GetMapping("/selectTicketimgs")
    @ApiOperation(value = "查询所有已购买票务",notes = "查询所有已购买票务")
    public Result<List<MovieTicketing>> selectTicketimgs(){
        List<MovieTicketing> movieTicketingList=new ArrayList<>();
        List<MovieTicketing> movieTicketings = movieTicketingService.list();
        for (MovieTicketing movieTicketing : movieTicketings) {
            if (movieTicketing.getOrderId()!=null){
                movieTicketingList.add(movieTicketing);
            }
        }
        return Result.getInstanceList(MovieTicketing.class).setData(movieTicketingList);
    }

}

